using Microsoft.Xna.Framework;

namespace XeoEngine
{
    class MainMenuScreen : MenuScreen
    {
        MenuEntry exitMenuEntry;
        MenuEntry optionsMenuEntry;
        MenuEntry SingleplayerMenuEntry;

        public MainMenuScreen()
            : base(Localizations.Strings.MainMenu)
        {
            SingleplayerMenuEntry = new MenuEntry(Localizations.Strings.Singleplayer);
            optionsMenuEntry = new MenuEntry(Localizations.Strings.Options);
            exitMenuEntry = new MenuEntry(Localizations.Strings.Exit);
            SingleplayerMenuEntry.Selected += SingleplayerMenuEntrySelected;
            optionsMenuEntry.Selected += OptionsMenuEntrySelected;
            exitMenuEntry.Selected += OnCancel;
            MenuEntries.Add(SingleplayerMenuEntry);
            MenuEntries.Add(optionsMenuEntry);
            MenuEntries.Add(exitMenuEntry);
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            exitMenuEntry.Text = Localizations.Strings.Exit;
            optionsMenuEntry.Text = Localizations.Strings.Options;
            SingleplayerMenuEntry.Text = Localizations.Strings.Singleplayer;
            MenuTitle = Localizations.Strings.MainMenu;
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        void SingleplayerMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.AddScreen(new SingleplayerScreen(), e.PlayerIndex);
        }

        void OptionsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.AddScreen(new OptionsMenuScreen(), e.PlayerIndex);
        }

        protected override void OnCancel(PlayerIndex playerIndex)
        {
            string message = Localizations.Strings.ExitWarn;
            MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen(message);
            confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;
            ScreenManager.AddScreen(confirmExitMessageBox, playerIndex);
        }

        void ConfirmExitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.Game.Exit();
        }
    }
}
